


/*
'===============================================================================
'  TuanHuy.BL.LanguageManagerBase
'===============================================================================
*/
#region Using
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TuanHuy.BLL;
using TuanHuy.DAL;
using TuanHuy.DAL.EntityClasses;
using TuanHuy.DAL.FactoryClasses;
using TuanHuy.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
#endregion

/*
'===============================================================================
'	
'  	
'  	
'  	
'  	
'	
'===============================================================================
*/
namespace TuanHuy.BLL
{
	///<summary>
	/// ModuleName:			Language
	/// CreatedBy:					
	/// CreatedDate:				4/8/2014 5:37:38 PM
	/// UpdatedBy:					<unknow>
	/// UpdatedDate:				<unknow>
	/// Description:				No Edit by User
	/// Notes for Update:	
	/// </summary>
	public class LanguageManagerBase:ManagerBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public LanguageManagerBase()
		{
			// Nothing for now.
		}
		
		/*public override string TableName()
        {
            return "Language";
        }*/
		
		public LanguageEntity Insert(LanguageEntity _LanguageEntity)
		{
			return Insert(_LanguageEntity, "");
		}
		
		public LanguageEntity Insert(LanguageEntity _LanguageEntity, string controlId)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(_LanguageEntity, true);
				LanguageFields field = new LanguageFields();
                //LogEntity(_LanguageEntity, field, AcInsert, controlId);
			}
			return _LanguageEntity;
		}

		
		public LanguageEntity Insert(decimal Id, string Language)
		{
			LanguageEntity _LanguageEntity = new LanguageEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_LanguageEntity.Id = Id;
				_LanguageEntity.Language = Language;
				LanguageFields field = new LanguageFields();
                //LogEntity(_LanguageEntity, field, AcInsert);
				adapter.SaveEntity(_LanguageEntity, true);
			}
			return _LanguageEntity;
		}

		
		public bool Update(LanguageEntity _LanguageEntity)
        {
            return Update(_LanguageEntity, "");
        }

		public bool Update(LanguageEntity _LanguageEntity, string controlId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(LanguageFields.Id == _LanguageEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_LanguageEntity, filter);
				toReturn = true;
				
				LanguageFields field = new LanguageFields();
                //LogEntity(_LanguageEntity, field, AcUpdate, controlId);
			}
			return toReturn;
		}
		
		public bool Update(LanguageEntity _LanguageEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_LanguageEntity, filter);
				toReturn = true;
				
				LanguageFields field = new LanguageFields();
                //LogEntity(_LanguageEntity, field, AcUpdate);
			}
			return toReturn;
		}

		public bool Update(decimal Id, string Language)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LanguageEntity _LanguageEntity = new LanguageEntity(Id);
				if (adapter.FetchEntity(_LanguageEntity))
				{
				
					_LanguageEntity.Language = Language;
					adapter.SaveEntity(_LanguageEntity, true);
					toReturn = true;
					
					LanguageFields field = new LanguageFields();
					//LogEntity(_LanguageEntity, field, AcUpdate);
				}
			}
			return toReturn;
		}

		public bool Delete(decimal Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LanguageEntity _LanguageEntity = new LanguageEntity(Id);
				if (adapter.FetchEntity(_LanguageEntity))
				{
					adapter.DeleteEntity(_LanguageEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("LanguageEntity", null);
			}
		}
		
		
		public int DeleteById(decimal Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LanguageEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLanguage(string Language)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Language == Language);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("LanguageEntity", filter);
			}
			return toReturn;
		}
		

		
		public LanguageEntity SelectOne(decimal Id)
		{
			LanguageEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				LanguageEntity _LanguageEntity = new LanguageEntity(Id);
				if (adapter.FetchEntity(_LanguageEntity))
				{
					toReturn = _LanguageEntity;
				}
			}
			return toReturn;
		}

		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LanguageCollection = new EntityCollection(new LanguageEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LanguageCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectAllLST()
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, null, 0, null);
			}
			return _LanguageCollection;
		}
		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectAllLST_Paged(int PageNumber, int PageSize)
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, null, 0, null, null, PageNumber, PageSize);
			}
			return _LanguageCollection;
		}


		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectByIdLST(decimal Id)
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, filter, 0, null);
			}
			return _LanguageCollection;
		}
		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectByIdLST_Paged(decimal Id, int PageNumber, int PageSize)
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LanguageCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(decimal Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LanguageCollection = new EntityCollection(new LanguageEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LanguageCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT_Paged(decimal Id, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LanguageCollection = new EntityCollection(new LanguageEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LanguageCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectByLanguageLST(string Language)
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Language == Language);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, filter, 0, null);
			}
			return _LanguageCollection;
		}
		
		// Return EntityCollection<LanguageEntity>
		public EntityCollection<LanguageEntity> SelectByLanguageLST_Paged(string Language, int PageNumber, int PageSize)
		{
			EntityCollection<LanguageEntity> _LanguageCollection = new EntityCollection<LanguageEntity>();
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Language == Language);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_LanguageCollection, filter, 0, null, null, PageNumber, PageSize);
			}
			return _LanguageCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLanguageRDT(string Language)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LanguageCollection = new EntityCollection(new LanguageEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Language == Language);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LanguageCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return DataTable
		public DataTable SelectByLanguageRDT_Paged(string Language, int PageNumber, int PageSize)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _LanguageCollection = new EntityCollection(new LanguageEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(LanguageFields.Language == Language);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_LanguageCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, 0, null, true, null, PageNumber, PageSize);
			}
			return toReturn;
		}
			
	}
}
